<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head>
    <base href="<%=basePath%>" />
    <title>Authorization User List</title>
    <script type="text/javascript">
		var path = "<%=basePath%>";
	</script>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>beshs/css/content.css" />
	<!-- 页面特效 -->
	<jsp:include page="/beshs/res-refer/page-effect-reference.jsp" />
	<script type="text/javascript" src="<%=basePath%>beshs/js/checkboxUtil.js"></script>
	<!-- 系统通用资源 -->
	<jsp:include page="/resources/resource-refer/common-resource-reference.jsp" />
	<!-- 用户访问菜单路径 -->
	<jsp:include page="/resources/usertrace/common-uservisit-reference.jsp" />
	<!-- 公共参数 -->
	<script type="text/javascript">
		//项目UID
		var projectUID = "<s:property value='projectUID' />";
		//授权角色
		var authorityRole = "<s:property value='authorityRole' />";
		//处理方法缓存
		var handleMethod = "<s:property value='handleMethod' />";
	</script>
  </head>
  <script type="text/javascript">
  	function addUserRole() {
  		<s:if test="!sysShareManager.equals(authorityRole)">
  			var idCounter = countCheckedBox("allChecked");
  			if(idCounter <= 0) {
				Dialog.alert("Please select users to be authorized！");
				return;
			}
			var idList = formatCheckedValue("allChecked");
  		</s:if>
		<s:else>
			var idCounter = $("input[name='radio_managerAuthority']:checked").size();
			if(idCounter <= 0) {
				Dialog.alert("Please select the user in need of resource permission！");
				return;
			}
			var idList = $("input[name='radio_managerAuthority']:checked").val();
		</s:else>
		$.getJSON(path+"authority/projectResourceConfigActionJson!saveRoleUserResAuthority.do?date="+new Date(), {
			projectUID: projectUID,
			authorityRole: authorityRole,
			userUIDList: idList
		}, function(data){
			if(data.success) {
				Dialog.alert("Successful Operation！", function() {
					//刷新当前页
					window.name = "__self";
					window.open(path+"authority/projectResourceConfigAction!queryRoleUserForProjResConfig.do?date="+new Date()
		  					+"&projectUID="+projectUID
				  			+"&authorityRole="+encodeURIComponent(authorityRole)
				  			+"&handleMethod="+handleMethod, "__self");
					//刷新父页面
					var pwin = window.dialogArguments;
					var requestLocation = path + "authority/projectResourceConfigAction!"+handleMethod+".do?date="+new Date()
							+"&projectUID="+projectUID;
					<s:if test="sysShareManager.equals(authorityRole)">
						pwin.parent.window.frames["managerMgrList"].location = requestLocation;
					</s:if>
					<s:if test="sysSalesman.equals(authorityRole)">
						pwin.parent.window.frames["salesMgrList"].location = requestLocation;
					</s:if>
					<s:if test="sysCardDistributor.equals(authorityRole)">
						pwin.parent.window.frames["cardDistributeMgrList"].location = requestLocation;
					</s:if>
				});
			} else {
				Dialog.alert("System error, please contact adminitrator！");
			}
		})
  	}
  	
  	$(function(){
  		$("input[name='query']").click(function(){
  			var userID = $("input[name='userID']").val();
  			window.name = "__self";
  			window.open(path+"authority/projectResourceConfigAction!queryRoleUserForProjResConfig.do?date="+new Date()
  					+"&userID="+encodeURIComponent(userID)
  					+"&projectUID="+projectUID
		  			+"&authorityRole="+encodeURIComponent(authorityRole)
		  			+"&handleMethod="+handleMethod, "__self");
  		});
  		$("input[name='add']").click(function(){
  			addUserRole();
  		});
  	});
  </script>
  <body>
  	<div class="content_all">
	  	<!--查询条件-->
	  	<div class="search">
	    	<form action="#"><table cellpadding="0" cellspacing="0">
	      		<tr>
	        		<th>User  Name：</th>
			        <td><input name="userID" value="<s:property value='userID' />" type="text" class="s_input" /></td>
			        <td><input name="query" type="button" value="Query" class="s_btn" />
	        			<input name="add" type="button" value="Add" class="s_btn" /></td>
	      		</tr>
	    	</table></form>
	  	</div>
	  	<!--查询列表-->
	  	<div class="search_table_all">
	    	<table class="search_table" cellspacing="0" cellpadding="0">
	      		<thead>
	        		<tr>
		          		<th style="width:50px;">
		          			<s:if test="!sysShareManager.equals(authorityRole)">
		          				<input id="allChecked" name="allChecked" type="checkbox" onclick="javascript:allCheck(this.id)"/>
		          			</s:if>
		          			<s:else>
		          				select
		          			</s:else>
		          		</th>
			          	<th>User  Name</th>
			          	<th>Gender</th>
			          	<th>ID Number</th>
	        		</tr>
	      		</thead>
	      		<tbody>
	      			<s:iterator value="userPage.list" var="user" status="status">
	      				<tr>
		          			<td>
		          				<s:if test="!sysShareManager.equals(authorityRole)">
		          					<input id="checkbox_<s:property value='#user.id'/>" type="checkbox" name="checkbox_<s:property value='#user.id'/>" value="<s:property value='#user.id'/>" onclick="javascript:clickTr(this.id)" />
		          				</s:if>
		          				<s:else>
		          					<input id="radio_<s:property value='#user.id'/>" type="radio" name="radio_managerAuthority" value="<s:property value='#user.id'/>" />
		          				</s:else>
		          			</td>
		          			<td><s:property value="#user.userID" /></td>
		          			<td>
		          				<s:if test="#user.gender=='male'">Male</s:if>
		          				<s:elseif test="#user.gender=='female'">Female</s:elseif>
		          			</td>
		          			<td><s:property value="#user.pid" /></td>
		        		</tr>
	      			</s:iterator>
	      		</tbody>
	    	</table>
	  	</div>
	  	<!--操作按钮&分页-->
	  	<script type="text/javascript">
	  		function pageUp(pageIndex) {
	  			var userID = $("input[name='userID']").val();
	  			var requestLocation = path+"authority/projectResourceConfigAction!queryRoleUserForProjResConfig.do?pageIndex="+(pageIndex-1)
	  					+"&userID="+encodeURIComponent(userID)
	  					+"&projectUID="+projectUID
			  			+"&authorityRole="+encodeURIComponent(authorityRole)
			  			+"&handleMethod="+handleMethod
	  					+"&date="+new Date();
	  			window.name = "__self";
	  			window.open(requestLocation, "__self");
	  		}
	  		
			function pageDown(pageIndex) {
				var userID = $("input[name='userID']").val();
				var requestLocation = path+"authority/projectResourceConfigAction!queryRoleUserForProjResConfig.do?pageIndex="+(pageIndex+1)
						+"&userID="+encodeURIComponent(userID)
						+"&projectUID="+projectUID
			  			+"&authorityRole="+encodeURIComponent(authorityRole)
			  			+"&handleMethod="+handleMethod
						+"&date="+new Date();
	  			window.name = "__self";
	  			window.open(requestLocation, "__self");
	  		}
			
			function pageLocate(pageIndex) {
				var userID = $("input[name='userID']").val();
				var requestLocation = path+"authority/projectResourceConfigAction!queryRoleUserForProjResConfig.do?pageIndex="+pageIndex
						+"&userID="+encodeURIComponent(userID)
						+"&projectUID="+projectUID
			  			+"&authorityRole="+encodeURIComponent(authorityRole)
			  			+"&handleMethod="+handleMethod
						+"&date="+new Date();
	  			window.name = "__self";
	  			window.open(requestLocation, "__self");
			}
	  	</script>
	  	<div class="search_control">
	    	<div class="right">
	      		<div class="pages">
	      		<!-- 上一页 -->
	      			<s:if test="pageIndex==1">
	      				<a href="javascript:void(0)" class="disabled">Former Page</a>
	      			</s:if>
	      			<s:else>
	      				<a href="javascript:pageUp(<s:property value='pageIndex' />)">Former Page</a>
	      			</s:else>
	      		<!-- 页码 -->
	      			<s:if test="pageSize<=0">
	      			<!-- 若分页页数未初始化或为0，则只显示第一页 -->
	      				<a href="javascript:void(0)" class="current">1</a>
	      			</s:if>
	      			<s:elseif test="pageSize<=9">
	      			<!-- 页数在9页以内全显示 -->
	      				<s:bean name="org.apache.struts2.util.Counter" id="counter">
	      					<s:param name="first" value="1" />
	      					<s:param name="last" value="pageSize" />
	      					<s:iterator value="counter" var="index">
	      						<s:if test="#index==pageIndex">
		      						<a href="javascript:void(0)" class="current"><s:property value="#index" /></a>
		      					</s:if>
		      					<s:else>
		      						<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
		      					</s:else>
	      					</s:iterator>
	      				</s:bean>
	      			</s:elseif>
	      			<s:else>
	      			<!-- 页数在9页以上则部分显示 -->
	      				<s:if test="pageIndex<7">
	      				<!-- 页码小于7时，先显示前7页 -->
	      					<s:bean name="org.apache.struts2.util.Counter" id="frontCounter">
	      						<s:param name="first" value="1" />
	      						<s:param name="last" value="7" />
	      						<s:iterator value="frontCounter" var="index">
	      							<s:if test="#index==pageIndex">
			      						<a href="javascript:void(0)" class="current"><s:property value="#index" /></a>
			      					</s:if>
			      					<s:else>
			      						<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
			      					</s:else>
	      						</s:iterator>
	      					</s:bean>
	      					...
	      				<!-- 显示最后两页 -->
	      					<s:bean name="org.apache.struts2.util.Counter" id="lastCounter">
	      						<s:param name="first" value="pageSize-1" />
	      						<s:param name="last" value="pageSize" />
	      						<s:iterator value="lastCounter" var="index">
	      							<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
	      						</s:iterator>
	      					</s:bean>
	      				</s:if>
	      				<s:elseif test="pageIndex>=7 && (pageSize-pageIndex)>2">
	      				<!-- 页码不小于7，但又不接近总页数时，分三部分显示：1-3、中间三页、最后一页 -->
	      					<s:bean name="org.apache.struts2.util.Counter" id="frontCounter">
	      						<s:param name="first" value="1" />
	      						<s:param name="last" value="3" />
	      						<s:iterator value="frontCounter" var="index">
	      							<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
	      						</s:iterator>
	      					</s:bean>
	      					...
	      					<s:bean name="org.apache.struts2.util.Counter" id="middleCounter">
	      						<s:param name="first" value="pageIndex-1" />
	      						<s:param name="last" value="pageIndex+1" />
	      						<s:iterator value="middleCounter" var="index">
	      							<s:if test="#index==pageIndex">
			      						<a href="javascript:void(0)" class="current"><s:property value="#index" /></a>
			      					</s:if>
			      					<s:else>
			      						<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
			      					</s:else>
	      						</s:iterator>
	      					</s:bean>
	      					...
	      					<a href="javascript:pageLocate(<s:property value='pageSize' />)"><s:property value="pageSize" /></a>
	      				</s:elseif>
	      				<s:else>
	      				<!-- 页码接近总页数，而且页码与总页数的差小于等于2时，分两部分显示：1-3、最后6页 -->
	      					<s:bean name="org.apache.struts2.util.Counter" id="frontCounter">
	      						<s:param name="first" value="1" />
	      						<s:param name="last" value="3" />
	      						<s:iterator value="frontCounter" var="index">
	      							<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
	      						</s:iterator>
	      					</s:bean>
	      					...
	      					<s:bean name="org.apache.struts2.util.Counter" id="lastCounter">
	      						<s:param name="first" value="pageSize-5" />
	      						<s:param name="last" value="pageSize" />
	      						<s:iterator value="lastCounter" var="index">
	      							<s:if test="#index==pageIndex">
			      						<a href="javascript:void(0)" class="current"><s:property value="#index" /></a>
			      					</s:if>
			      					<s:else>
			      						<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
			      					</s:else>
	      						</s:iterator>
	      					</s:bean>
	      				</s:else>
	      			</s:else>
	      		<!-- 下一页 -->	
	      			<s:if test="pageSize>pageIndex">
	      				<a href="javascript:pageDown(<s:property value='pageIndex' />)">Next Page</a>
	      			</s:if>
	      			<s:else>
	      				<a href="javascript:void(0)" class="disabled">Next Page</a>
	      			</s:else>
	      		</div>
	    	</div>
	    	<div class="clear"></div>
	  	</div>
	  	<!-- 分页结束 -->
	</div>
  </body>
</html>
